﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Umbrella.Net.Contracts;
using Umbrella.Whs.SharePoint;

namespace Umbrella.Whs.WhsAddin.Wizards.SharePointInstallation
{
    internal class InstallStepSharePointSetup : IInstallStep
    {
        private InstallationPackagesManager _ipm = new InstallationPackagesManager();
        private SharePointInstallationFile _ip;

        public InstallStepSharePointSetup(SharePointInstallationFile ip, string ipTitle)
        {
            if (string.IsNullOrEmpty(ipTitle))
                throw new ArgumentException("null or empty", "ipTitle");

            _ip = ip;

            this.Title = string.Format(
                Resources.txtInstallingSharePoint,
                ipTitle
                );

            this.Weight = (InstallationManager.RootLanguageLCID == ip.LanguageLCID ? 310 : 80);
        }

        public string Title
        {
            get; 
            private set;
        }

        public int Weight
        {
            get;
            private set;
        }

        public void PerformInstall()
        {
            var spDir = _ipm.GetExtractionDirectory(_ip).FullName;

            var pi = new RunProcessLogged(
                Path.Combine(spDir, "setup.exe"),
                "/config \"" + Path.Combine(InstallationManager.InstallationConfigAndLogDir, "config.xml") + "\"",
                spDir
            );

            pi.Run();
        }
    }
}
